package com.matrix.order.infrastructure.persistence.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.matrix.order.infrastructure.persistence.po.OrderItemPO;
import org.apache.ibatis.annotations.MapKey;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

/**
 * @author 有点甜
 * @since 2025/7/27
 */
@Mapper
public interface OrderItemMapper extends BaseMapper<OrderItemPO> {

    @MapKey("shop_id")
    Map<Long, Map<String, Object>> sumSalesByShopIdsAfterDate(
            @Param("shopIds") List<Long> shopIds,
            @Param("date") LocalDateTime date
    );

    @MapKey("product_id")
    List<Map<String, Object>> sumProductSalesAfterDate(@Param("date") LocalDateTime date);

    @Select("SELECT order_id FROM t_order_item WHERE id = #{orderItemId} LIMIT 1")
    Long findOrderIdByOrderItemId(@Param("orderItemId") Long orderItemId);
}
